package com.lovo.roomProject.room.service.impl;

import com.lovo.roomProject.pojo.CutPageBean;
import com.lovo.roomProject.pojo.RoomDO;
import com.lovo.roomProject.room.dao.impl.RoomDAOImpl;
import com.lovo.roomProject.room.dao.RoomDAO;
import com.lovo.roomProject.room.service.RoomService;

import java.sql.SQLException;
import java.util.List;

public class RoomServiceImpl implements RoomService {
    RoomDAO roomDAO = new RoomDAOImpl();

    @Override
    public List listRoom() {
        return roomDAO.listRoom();
    }

    @Override
    public List listRoomByType(String type) {
        return roomDAO.listRoomByType(type);
    }

    @Override
    public CutPageBean listRoomByPage(int current,String addr,String status,String enable,String type){
        return roomDAO.listRoomByPage(current,addr,status,enable,type);
    }

    @Override
    public RoomDO getRoomById(int id) {
        return roomDAO.getRoomById(id);
    }

    @Override
    public void insert(RoomDO roomDO) {
        roomDAO.insert(roomDO);
    }

    @Override
    public void delete(int id) throws Exception {
        RoomDO roomDO = getRoomById(id);
        if (roomDO.getInCount()>0){
            throw new Exception("房间有人入住,不能删除") ;
        }
        roomDAO.delete(id);
    }

    @Override
    public List listStudentById(int id) {
        return roomDAO.listStudentById(id);
    }

}
